import json
import sys
sys.path.append('../')
from matplotlib import pyplot as plt
from matplotlib import gridspec
import matplotlib
from utils import *
f = open('Data/metadata.json')
metadata = json.load(f)
# view metadata present in the file
metadata
{'min_pitch': 220,
'max_pitch': 880,
'start_time': 1140,
'duration': 30,
'sitar_audio_path': 'Data/NIR_ABh_Puriya_Sitar1.wav',
'mix_audio_path': 'Data/NIR_ABh_Puriya_StereoMix.wav',
'cycle_file': 'Data/NIR_ABh_Puriya_Metre_VilambitTeental.csv',
'onset_file': 'Data/NIR_ABh_Puriya_Onsets_Selected_VilambitTeental.csv',
'tonic': 293.66,
'notes': [{'label': 'D_', 'cents': -300},
{'label': 'N_', 'cents': -100},
{'label': 'S', 'cents': 0},
{'label': 'r', 'cents': 100},
{'label': 'G', 'cents': 400},
{'label': 'm', 'cents': 600},
{'label': 'D', 'cents': 900},
{'label': 'N', 'cents': 1100},
{'label': "S'", 'cents': 1200},
{'label': "r'", 'cents': 1300},
{'label': "G'", 'cents': 1600},
{'label': "m'", 'cents': 1800}],
'num_div': 4}
playAudio(audioPath=metadata['mix_audio_path'], startTime=metadata['start_time'], duration=metadata['duration'])
%%capture
# initialise figure, with 3 subplots
fig, axs = generateFig(3, (14, 7), [2, 3, 3])
# plot waveplot
axs[0] = drawWave(audioPath=metadata['mix_audio_path'], startTime=metadata['start_time'], duration=metadata['duration'], ax=axs[0], annotate=True, cyclePath=metadata['cycle_file'], numDiv=metadata['num_div'], annotLabel=False)
# plot spectrogram
axs[1] = spectrogram(audioPath=metadata['mix_audio_path'], startTime=metadata['start_time'], duration=metadata['duration'], cmap='Blues', ax=axs[1], yticks=True, annotate=True, onsetPath=metadata['onset_file'], numDiv=metadata['num_div'], annotLabel=True, cAnnot='red')
# plot pitch contour
axs[2] = pitchCountour(audioPath=metadata['sitar_audio_path'], startTime=metadata['start_time'], duration=metadata['duration'], minPitch=metadata['min_pitch'], maxPitch=metadata['max_pitch'], notes=metadata['notes'], tonic=metadata['tonic'], ax=axs[2], annotate=True, cyclePath=metadata['cycle_file'], numDiv=metadata['num_div'], xticks=True, yticks=True)
# display figure
fig
playAudioWClicks(audioPath=metadata['mix_audio_path'], startTime=metadata['start_time'], duration=metadata['duration'], onsetFile=metadata['onset_file'], onsetLabels=['Inst'])